using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Calculate
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btn_Click_Click(object sender, EventArgs e)
{
int r, Cal = 0;
int n = Convert.ToInt32(txt_Integer.Text);
while(n!=0)
{
r = n % 10;
n = n / 10;
Cal = Cal + r;
}
//MessageBox.Show(Cal.ToString());
lbl_Show.Text = Cal.ToString();
txt_Integer.Text = "";
}
}
}
این همین برنامه بالاست منتها با کلاس بندی:
کلاس:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Calculate_Class
{
public class RectAngle
{
public int tool;
public int arz;
public RectAngle(int Tool, int Arz)
{
arz = Arz;
tool = Tool;
}
public int Masahat()
{
int s = tool * arz;
return s;
}
public int Mohit()
{
int m = (tool + arz) * 2;
return m;
}
}
}
فراخونی:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Calculate_Class
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public RectAngle RectAngle;
private void button1_Click(object sender, EventArgs e)
{
RectAngle = new RectAngle(Convert.ToInt32(textBox1.Text),Convert.ToInt32(textBox2.Text));
int c = RectAngle.Masahat();
int z = RectAngle.Mohit();
MessageBox.Show(" Masahat: "+c.ToString() +" "+" Mohit: "+z.ToString());
این یک برنامه ساده برای محاسبات حقوقی کارمندان هست
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Hoghogh
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
اینم یه برنامه ساده دیگس که میاد یک سری محاسبات برای گرم و کیلوگرم انجام میده که در واقع با کلاس نوشته شده:
کلاس:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Karmand
{
class Class
{
public int a;
public double gram;
public double kgram;
public Class(int A)
{
a = A;
}
public double GRAM()
{
gram = a * 0.453595;
return gram;
}
public double KGRAM()
{
kgram = a * 453.59237;
return kgram;
}
}
}
فراخونی:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Karmand
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Class C = new Class(Convert.ToInt32(textBox1.Text));
double D = C.GRAM();
double U = C.KGRAM();
label1.Text = D.ToString() + "\n" + U.ToString();
}
}
}
علاقه مندی ها (Bookmarks)